import { Controller, Get, Post, Body, Patch, Param, Delete,Req,Query } from '@nestjs/common';
import { DeptService } from './dept.service';
import { CreateDeptDto } from './dto/create-dept.dto';
import { UpdateDeptDto } from './dto/update-dept.dto';
import { QueryDeptDto } from './dto/query-dept.dto';
import { ApiTags,ApiOperation,ApiBearerAuth } from '@nestjs/swagger';
import { Request } from 'express';
import { RequirePermission } from 'src/decorator/reuqire-permission';

@Controller('dept')
@ApiTags('部门管理')
@ApiBearerAuth()
export class DeptController {
  constructor(private readonly deptService: DeptService) {}

  @Post()
  @ApiOperation({summary:'创建部门'})
  @RequirePermission("system:dept:add")
  create(@Body() createDeptDto: CreateDeptDto,@Req() request:Request) {
    return this.deptService.create(createDeptDto,request);
  }

  @Get()
  @ApiOperation({summary:'获取部门列表'})
  @RequirePermission("system:dept:list")
  findAll(@Query() query:QueryDeptDto) {
    return this.deptService.findAll(query);
  }

  @Get(':id')
  @ApiOperation({summary:'获取部门详情'})
  @RequirePermission("system:dept:edit")
  findOne(@Param('id') id: string) {
    return this.deptService.findOne(+id);
  }

  @Patch(':id')
  @ApiOperation({summary:'更新部门'})
  @RequirePermission("system:dept:edit")
  update(@Param('id') id: string, @Body() updateDeptDto: UpdateDeptDto,@Req() request:Request) {
    return this.deptService.update(+id, updateDeptDto,request);
  }

  @Delete(':id')
  @ApiOperation({summary:'删除部门'})
  @RequirePermission("system:dept:remove")
  remove(@Param('id') id: string) {
    return this.deptService.remove(+id);
  }
}
